package com.jizhang.service.impl;

import com.jizhang.base.model.BaseModel;
import com.jizhang.entity.Info;
import com.jizhang.mapper.InfoMapper;
import com.jizhang.service.InfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 郭博民
 * @since 2022-07-16
 */
@Service
public class InfoServiceImpl extends ServiceImpl<InfoMapper, Info> implements InfoService {
    @Autowired
    InfoMapper infoMapper;

    // 添加一笔
    public BaseModel addInfo(Info info, BaseModel baseModel) throws Exception {
        int num = infoMapper.addInfo(info);
        if (num<=0){
            // 二者用一   throw new BusinessException(1002, "添加题目失败");
            baseModel.setCode(1007);
            baseModel.setMessage("记一笔添加失败");
            return baseModel;
        }
        baseModel.setCode(0);
        baseModel.setMessage("记一笔成功");
        return baseModel;
    }

    // 根据类型\月份 查询当月数据
    public BaseModel findAllInfo(Info info, BaseModel baseModel) throws Exception {
        System.out.println("传来的参数:"+info);
        List<Info> infoList =  infoMapper.findAllInfo(info);
        System.out.println("查询结果:"+infoList);
        baseModel.setCode(0);
        baseModel.setData(infoList);
        return baseModel;
    }

}
